package com.example.zhidao.dao;

//import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.example.zhidao.model.po.Comments;
import com.example.zhidao.model.po.Fans;
import com.example.zhidao.model.vo.CommentVo;

import com.github.yulichang.base.MPJBaseMapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import java.awt.print.Pageable;
import java.util.List;

public interface CommentsMapper extends MPJBaseMapper<Comments> {
//    // 查询一级评论
//    @Select("SELECT * FROM comments WHERE bid=#{bid} AND type=1")
//    List<Comments>  getCommentList(String bid);
//
////    查询二级评论
//    @Select("SELECT * FROM comments WHERE bid=#{bid} AND type=2")
//    List<Comments> getChildrenComment(String bid);


//    查找一级分类（已弃用，采取下面的xml）
    @Select("SELECT c.*, u.username, u.img FROM comments c LEFT JOIN user u ON c.uid = u.id WHERE c.bid=#{bid} and c.type=1 order " +
            "bY c.createtime Asc")
    public List<CommentVo> selone(String bid);

    @Select("SELECT c.*, u.username, u.img, IF(g.id IS NOT NULL, 1, 0) AS is_liked FROM comments c LEFT JOIN user u ON c.uid = u.id "+
            " LEFT JOIN cgoods g ON g.cid = c.id and g.uid=#{mid}"+
            "WHERE c.bid=#{bid} and c.type=2 and topid=#{uid} order " +
            "bY c.createtime Asc")
    public List<CommentVo> seltwo(String bid,String uid,String mid);


//    采取xml形式进行开发
     List<CommentVo> one(String bid, String uid,@Param("pageNum")int pageName, @Param("pageSize")int pageSize);


    @Update("UPDATE comments SET good = good + 1 WHERE id = #{id}")
    public int addcoomgood(String id);

    @Update("UPDATE comments SET good = good - 1 WHERE id = #{id}")
    public int delcoomgood(String id);
}
